package cn.cmdr.vo;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ResultVo {
    /**
     * 响应状态a
     */
    private int code;
    /**
     * 响应信息
     */
    private String msg;
    /**
     * 返回数据
     */
    private Object result;
    private Integer cd;

    /**
     * 增删改成功
     * @param msg
     * @return
     */
    public static ResultVo sucess(String msg){
        ResultVo resultVo = new ResultVo();
        resultVo.setCode(1000);
        resultVo.setMsg(msg);
        return resultVo;
    }
    /**
     * 查询成功
     * @param result
     * @return
     */
    public static ResultVo sucess(Object result){
        ResultVo resultVo = new ResultVo();
        resultVo.setCode(1000);
        resultVo.setResult(result);
        return resultVo;
    }
    /**
     * 查询成功
     * @param result
     * @return
     */
    public static ResultVo sucess(Object result,Integer cd){
        ResultVo resultVo = new ResultVo();
        resultVo.setCd(cd);
        resultVo.setCode(1000);
        resultVo.setResult(result);
        return resultVo;
    }

    /**
     * 增删改失败
     * @param msg
     * @param e
     * @return
     */
    public static ResultVo fail(String msg,Exception e){
        ResultVo resultVo = new ResultVo();
        resultVo.setMsg(msg);
        resultVo.setCode(2000);
        log.error(msg,e);
        return resultVo;
    }

    /**
     * 查询失败
     * @param msg
     * @return
     */
    public static ResultVo fail(String msg){
        ResultVo resultVo = new ResultVo();
        resultVo.setMsg(msg);
        resultVo.setCode(2000);
        return resultVo;
    }
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getResult() {
        return result;
    }

    public void setResult(Object result) {
        this.result = result;
    }

    public Integer getCd() {
        return cd;
    }

    public void setCd(Integer cd) {
        this.cd = cd;
    }
}
